#ifndef _POLYHEDRON_H_
#define _POLYHEDRON_H_

#include <vector>
#include <vec.h>
#include <mat.h>

using namespace std;

typedef struct{
	int vert;
	int pair;
	int face;
	int next;
} Edge;

typedef struct{
	double x;
	double y;
	double z;
	double nx;
	double ny;
	double nz;
	int edge;
} Vert;

typedef struct  
{
	double nx;
	double ny;
	double nz;
	double d;
	int edge;
} Face;

typedef struct{
	int a;
	int b;
	int c;
} Tri;

typedef struct  
{
	int a;
	int b;
} Line;

typedef void(*initializeFunc)(Edge**, Vert**, Face**, int*, int*);
typedef vector<int> IndexList;



class Polyhedron
{
public:
	Polyhedron(void);
	~Polyhedron(void);

	void buildPolyStructure(initializeFunc setUp);
	void constructFaceNormal();
	void constructVertNormal();
	void setUpLines();

	void translatePolyhedron(Vec3d translate);
	void rotatePolyhedron(Mat33d rotate);

	Vert getVertexFromVertex(int index);
	void getOneRingVertexFromVertex(int index, IndexList** ring);
	int getVertexFromEdge(int index);

	Tri getEdgeFromFace(int index);
	Line getLineFromEdge(int index);

	Tri getFaceFromFace(int index);	
	void getOneRingFaceFromVertex(int index, IndexList** ring);	
	void getIncidentFaceFromEdge(int index, int** ops);
	
	double getIncidentFaceAngle(int f_Index, int v_Index);

	//void getSqrDistanceToFace(int f_Index, Vec3d pt, double* fSqrDist, double* fS, double* fT);
	Vec3d getPointFromST(int f_Index, double s, double t);
	Vec3d getNormalFromST(int f_Index, double s, double t);
	void getSqrDistance(Vec3d pt, double* sqrDist, Vec3d* closestPt, Vec3d* closestNormal);

	void getSqrDistanceToFace(int f_Index, Vec3d pt, double* fSqrDist, double* fS, double* fT);

	Edge* edgeList;
	Vert* vertList;
	Face* faceList;
	Line* lineList;

	int faceCount;
	int vertCount;
	int lineCount;
};

#endif



